package cm.android;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;

public class FormFile {
	private long mFileLen = 0;
	private long mFileMTime = 0;
	private String mFileName = null;
	private boolean mExist = false;
	FormFile(String filename) {
		File file = new File(filename);
		if (file.exists() == true) {
			mFileLen = file.length();
			mFileMTime = file.lastModified();
			mFileName = filename;
			mExist = true;
		}
	}
	
	public boolean exists() {
		return mExist;
	}
	
	public long length() {
		return mFileLen;
	}
	
	public long getMTime() {
		return mFileMTime;
	}
	
	public String getFileName() {
		return mFileName;
	}
	
	public boolean CopyToStream(OutputStream os) {
		boolean bRes = false;
		try {
			FileInputStream fis = new FileInputStream(mFileName);
			byte[] data = new byte[4096];
			
			while(true) {
				int rlen = fis.read(data);
				if (rlen == -1)
				{
					bRes = true;
					break;
				}
				os.write(data, 0, rlen);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return bRes;
	}
}
